home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 210 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  62 lines

  1. Path: news.cuny.edu!apccu
  2. From: Paul Abrilla <APCCU@CUNYVM.CUNY.EDU>
  3. Newsgroups: comp.lang.c++
  4. Subject: help on syntax
  5. Date: Tue, 2 Jan 1996 22:27:28 EST
  6. Organization: City University of New York/University Computer Center
  7. Message-ID: <96002.222728APCCU@CUNYVM.CUNY.EDU>
  8. NNTP-Posting-Host: cunyvm.cuny.edu
  9. Disclaimer: Author bears full responsibility for this post
  10.  
  11. Hi,
  12.  
  13. I'm trying to run a simple program, but I'm getting a 'misplaced
  14. else' error everytime I compile it.  However, when I tried to modify
  15. the program the if statement it ran perfectly fine.  Can anyone please
  16. tell me what's going on.  Program I is the original, and Program II
  17. is the modified version.  Any help will be appreciated.  Please send
  18. replies directly to my account.  Thanks.
  19.  
  20. PROGRAM I
  21.  
  22. #include <iostream.h>
  23. void main()
  24. {
  25.       int a, b, c;
  26.       cout << "Please enter three numbers¢n";
  27.       cout << "a: ";
  28.       cin >> a;
  29.       cout << "¢nb: ";
  30.       cin >> b;
  31.       cout << "¢nc: ";
  32.       cin >> c;
  33.  
  34.       if (c = (a-b))
  35.           cout << "a: ";
  36.           cout << a;
  37.           cout << " minus b: ";
  38.           cout << b;
  39.           cout << " quals c: ";
  40.           cout << c << endl;
  41.       else
  42.           cout << "a-b does not equal c: " << endl;
  43.  
  44. }
  45.  
  46.  
  47. PROGRAM II
  48.  
  49. :
  50. :
  51. :
  52.     if (c = (a-b))
  53.          cout << "a: " << a << " minus b: " << b << " equals c: " << c;
  54.     else
  55.          cout << "a-b does not equal c: ";
  56. }
  57.  
  58.  
  59. -----------
  60. Paul
  61. email: apccu@cunyvm.cuny.edu
  62.